
#include <sstream>
#include "../include/ty_util.h"


namespace tylenol { namespace util {


bool IsInternalIP(std::string &str)
{
	std::string ip1("192.");
	std::string ip2("10.");

	if(ip1.compare(0, ip1.size(), str, 0, ip1.size()) == 0)
	{
		return true;
	}
	else if(ip2.compare(0, ip2.size(), str, 0, ip2.size()) == 0)
	{
		return true;
	}

	return false;
}

std::vector<std::string> split( std::string& str, std::string separators )
{
	size_t n = str.length();
	size_t start, stop;
	std::vector<std::string> result;
	start = str.find_first_not_of( separators );

	while (( start >= 0 ) && ( start < n ))
	{
		stop = str.find_first_of(separators, start);
		if (( stop < 0) || (stop > n )) stop	=	n;
		result.push_back( str.substr( start, stop - start ) );
		start = str.find_first_not_of( separators, stop+1 );
	}
	return result;
}

// for packet cryption
void xorEncode(unsigned char* src, int srclen, unsigned char* key, int keylen, unsigned char* ret)
{
    for(int i=0, k=0; i<srclen; ++i)
    {
        ret[i] = src[i] ^ key[k];

        if( ++k >= keylen )
            k = 0;
    }
}



} /*util*/ } /*tylenol*/
